package com.woniuxy.controller;

import com.woniuxy.commons.entity.Medicine;
import com.woniuxy.commons.entity.Prescription;
import com.woniuxy.commons.entity.User;
import com.woniuxy.commons.service.MedicineService;
import com.woniuxy.commons.service.PrescriptionService;
import com.woniuxy.commons.service.UserService;
import com.woniuxy.commons.utils.ResponseResult;

import com.woniuxy.entity.PrescriptionOrder;
import com.woniuxy.service.PrescriptionOrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/order")
public class PrescriptionOrderController {
    @Resource
    MedicineService MedicineService;
    @Resource
    PrescriptionService prescriptionService;
    @Resource
    UserService userService;
    @Resource
    PrescriptionOrderService prescriptionOrderService;
    @ApiOperation(value = "获取所有流转订单数据")
    @GetMapping("/prescriptionOrder/findAll/{currentPage}/{pageSize}")
    public ResponseResult findAll(@ApiParam(name = "currentPage", value="当前页码",required=true)@PathVariable int currentPage,
                                  @ApiParam(name = "pageSize", value="页面大小",required=true)@PathVariable int pageSize){

        return prescriptionOrderService.findAll(currentPage,pageSize);
    }
    @PostMapping("/prescriptionOrder/search")
    public ResponseResult search(@RequestBody PrescriptionOrder prescriptionOrder){

        return  prescriptionOrderService.search(prescriptionOrder);
    }
    @GetMapping("/prescriptionOrder/user/findByRecord/{id}")
    public ResponseResult<User> findByRecord(@PathVariable(value="id") int id){
        return userService.findByRecord(id);
    };
    @GetMapping("/prescriptionOrder/prescription/findMedicineIdsByPid/{id}")
    ResponseResult findMedicineIdsByPid( @PathVariable int id){
        return prescriptionService.findMedicineIdsByPid(id);
    }
    @PostMapping("/prescriptionOrder/medicine/medicine/batchFind")
    public ResponseResult<List<Medicine>> findBatch(@RequestBody int[] ids){
        System.out.println(Arrays.toString(ids));
        return MedicineService.findBatch(ids);
    }
    @GetMapping("/prescriptionOrder/prescription/findById/{id}")
    ResponseResult<Prescription> findById(@PathVariable(value = "id") int id){
        return prescriptionService.findById(id);
    };
    @PutMapping("/prescriptionOrder/update")
    @ApiOperation(value = "修改发药状态")
    public ResponseResult updateOne(@RequestBody PrescriptionOrder prescriptionOrder){
        return prescriptionOrderService.updateOne(prescriptionOrder);
    }
    @DeleteMapping("/prescriptionOrder/delete/{id}")
    @ApiOperation(value = "删除处方")
    public ResponseResult deleteOne(@PathVariable int id){
        return prescriptionOrderService.deleteOne(id);
    }
}
